﻿<!doctype html>
<html><!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>产品促销价格管理</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<script type="text/javascript" src="../js/find.js"></script> 
<script type="text/javascript" src="../js/goodsSelecter.js"></script> 
<script type="text/javascript" src="../js/pagination.js"></script> 
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" >
$(function(){
	refreshInput($(".serWrapper"));
	$('.doubledate').kuiDate({
		className:'doubledate',
		isDisabled: "0"  // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
});
function bclicks(obj){
	var $first=obj.parent("td").parent("tr").children("td:first");
	var id=$first.html();
	var name=$first.next().html();
	//$("#shopName").children("option").blur();
	getParamToshopS(id,name)
}
$(function(){
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
		}else{
			$("#shopName").attr("disabled",true);
		}
	})
	addMargin($("#window_change"));
	
	_goodsId=getIdByName("goodsId");
	getGoodsInfo(1)
})


function toAdd(){
	$("#doflag").val(1);
	resetForm();
	$("#yinying1,#window_change").show();

}
function toUpdate(id,shopId,obj){
	resetForm();
	$("#doflag").val(2);
	$("#updateId").val(id)
	for ( var i = 0; i < rst.result.data.length; i++) {
		var ids=getHtmlInt(getHeadIndexValue(i, rst, "RuleID"));
		if(id==ids){
			var option="<option value='"+getHtmlString(getHeadIndexValue(i, rst, "shopId"))+"'>"+getHtmlString(getHeadIndexValue(i, rst, "shopName"))+"</option>";
			$("#shopName2").html(option);
			$("#RuleName").val(getHtmlString(getHeadIndexValue(i, rst, "RuleName")));
			$("#status").val(getHtmlString(getHeadIndexValue(i, rst, "Status")));
			$("#RuleType").val(getHtmlString(getHeadIndexValue(i, rst, "RuleType")));
			$("#schedName").val(getHtmlString(getHeadIndexValue(i, rst, "ScheduleTypeName")));
			_schedTypeId = _getStringOfJson(i, rst, "ScheduleTypeId")
			var ConsumeType=getHtmlString(getHeadIndexValue(i, rst, "ConsumeType"))
			if(ConsumeType=="固定积分"){
				$("#chooseJifen").val("1")
				$("#showJifen").html("固定积分")

				$("#jifen").val(getHtmlString(getHeadIndexValue(i, rst, "FixedIntegral")))
			}else{
				$("#showJifen").html("积分比率")
				$("#chooseJifen").val("0")
				$("#jifen").val(getHtmlString(getHeadIndexValue(i, rst, "IntegralRate")))

			}
			
		}
	}
	
	$("#yinying1,#window_change").show();
}

function getParamToshopS(id,name){
	var htm="<option value='"+id+"'>"+name+"</option>"
	var shopflag=$("#shopflag").val();
	if(shopflag==1){
	$("#shopName").html(htm);
	$("#shopName").val(id);
	}else{
		$("#shopName2").html(htm);
		$("#shopName2").val(id);	
	}
	closeShopShow();
}

function closeShopShow(){
	$("#shopShow,#yinying").hide();
	$("#searchName").val("");
}

function InitShopList(page){
	var shopName=$("#searchName").val();
	if(IsNotEmpty(page)){
		shopPageIndex = page
	}else{
		shopPageIndex = 1;
	}
	$.ajax({
		type : "post",
		async:false,
		data :'name='+shopName,
		datatype : "json",
		url : "../shop/find/shopList/" + (shopPageIndex -1) + "/5",
		success : function(data) {
			var rst = JSON.parse(data);
			if(IsEmpty(rst)){
				art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
				return false;
				}
				if(rst.state==0){
					$("#shopList tbody tr").remove();

					initShopTable(rst);
					$("table[id='shopList'] tbody tr").each(function(){
						$(this).children("td:last").css("text-align","center").append("<input type='button' class='common_btn' value='选择' onclick='bclicks($(this))'>");

					})	
					if(rst.result.len > 0){
						 var shu = rst.result.len;
						 shopCount = Math.ceil(shu/5);					
						 }else{
								shopCount==0;
						 }
					 $("#shopPager").pager({ pagenumber: shopPageIndex, pagecount: shopCount, buttonClickCallback: ShopPageClick });
					 addMargin($("#shopShow"));	
					 }else if(rst.state==1){
					art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
		}	
	});	
}

function getInfoOfGoodsId(pricePageIndex) {
	if(IsNotEmpty(pricePageIndex)){
		_pricePageIndex = pricePageIndex	
	}
	var shopId="";
	var param=null;
	if($("#shopIsChoosed").is(":checked")){
		shopId=$("#shopName").val();
		if(shopId!=""&&shopId!=null){
			param={'goodsId':_goodsId,'shopId':shopId};
		}else{
			param={'goodsId':_goodsId}
		}
	}else{
		param={'goodsId':_goodsId}
	}
	
	_priceJson =_findInfo("../goodsPromPrice/find/goodsPromPriceList/" + (_pricePageIndex-1) + "/10", param);
		if(_priceJson.state==0){
			var params = new Array("shopName","goodsCode","goodsName","salePrice","promPrice","effectDate","unEffectDate","memo","staName","subman")
			_loadInfoOfUpdateAndDelete(_priceJson, "memberList", "toUpdatePrice", "deletePrice", params, "id")
			_loadPage("pager", _pricePageIndex, 10, _priceJson, getInfoOfGoodsId)
			$("#sup").html("共"+_priceJson.result.len+"条");									
		}
}

ShopPageClick = function(pageclickednumber) {
    InitShopList(pageclickednumber);
}


function search2(){
	InitShopList(1);
}

function initShopTable(json){
	if(json!=null && json.state==0){
		var params = new Array("id", "name","mp","contact");
		Loadtable(json,params,"shopList");
	}
}


function Loadtable(json, params, tableId){
	var phArray = new Array();
	var count = 0;
	if (params != null) {
		$(params).each(function(pIndex, pData) {
			$.each(json.result.head, function(hIndex, hData) {
				if (pData == hData) {
					phArray[count++] = hIndex;
				}
			});
		});
	}
	if (json.result.data != null) {
		$.each(json.result.data, function(index, dt) {
			$("table[id='" + tableId + "']").append("<tr></tr>");
			$(phArray).each(function(phIndex, data) {
				$.each($(dt), function(dtIndex, d) {
					if (dtIndex == data) {
						$("table[id='" + tableId + "'] tr:last").append("<td>" +  (d === null||d=="null" ? " " : d) + "</td>");
					}
				});
			});
		});
	}
}

function showShopList(type){
	$("#shopflag").val(type)		
		$("#shopName").blur();
		$("#shopName2").blur();
	$("#shopShow,#yinying").show();
	InitShopList(1);
}

function  downRescouse(){
var code=$("#code").val().replace(/\s/gi,'');
	var shopId="";
	var param='code='+code;
	if($("#shopIsChoosed").is(":checked")){
		shopId=$("#shopName").val();
		if(shopId!=""&&shopId!=null){
			param+="&shopId="+shopId;
		}
	}
	param+="&downType=8"
	window.location.href="../csvdown/down/csv/down?"+param
}

function resetForm(){
	$("#close_this").attr("disabled",false)
	$("#shopName2").html("");
	$("#promPrice").val("");
	$("#enableTime").val("");
	$("#disableTime").val("");
	$("#memo").val("");

	
}

function saveInfo(){
	var doflag=$("#doflag").val();
	if(doflag==1){
  		addInfo();
	}else if(doflag==2){
		updateInfo()
	}else{
			art.dialog({fixed:true, lock: true,content:"页面出错",icon:'error',ok:true});	
		window.location.reload();
	}
}

function addInfo(){

	var shopId=$("#shopName2").val();
	var promPrice=$("#promPrice").val().replace(/\s/gi,'');
	var enableTime=$("#enableTime").val().replace(/\s/gi,'');
	var disableTime=$("#disableTime").val().replace(/\s/gi,'');
	var memo=$("#memo").val().replace(/\s/gi,'');
	var status=$("#status").val().replace(/\s/gi,'');
	if(checkNull(_goodsId,"产品",null)&&checkNull(shopId,"店铺","shopName2")&&_checkMoney(promPrice, false, "促销价格", "#promPrice")&&checkNull(enableTime, "生效时间", null)&&checkNull(disableTime, "失效时间", null)){
	}else{
		return false
	}
	var heads=new Array("shopId","promPrice","Status","effecDate","uneffedDate","memo","goodsId")
	var datas=new Array(shopId,promPrice,status,enableTime,disableTime,memo,_goodsId);
	var jsonParserStr = _getJsonParseInsertStr(heads, datas);
	
	var dt = _insertInfo("../goodsPromPrice/insert/insertInfo", {"data":jsonParserStr})
			if(dt.state==0){
				getInfoOfGoodsId(1);
				$("#yinying1,#window_change").hide();
				resetForm();
				 }
}

function deletePrice(id){
	art.dialog({fixed:true, lock: true,content:"确认删除该条数据？",icon:'question',ok: function(){
		var dt= _deleteInfo("../goodsPromPrice/del/deleteInfo", {"id":id})
		if(dt.state==0){
			getInfoOfGoodsId(null);
		}	
		
	},cancel:true});

	
}
function toUpdatePrice(id){
	$("#doflag").val(2);
	$("#updateId").val(id);

	resetForm();
	for ( var i = 0; i < _priceJson.result.data.length; i++) {
		var ids= _getIntOfJson(i, _priceJson, "id")
		if(id==ids){
			var htm="<option value='"+_getStringOfJson(i, _priceJson, "shopId")+"'>"+_getStringOfJson(i, _priceJson, "shopName")+"</option>"
			$("#shopName2").html(htm);
			$("#promPrice").val(_getStringOfJson(i, _priceJson, "promPrice"));
			$("#enableTime").val(_getStringOfJson(i, _priceJson, "effectDate").substring(0,10));
			$("#disableTime").val(_getStringOfJson(i, _priceJson, "unEffectDate").substring(0,10));
			$("#memo").val(_getStringOfJson(i, _priceJson, "memo"));
			$("#status").val(_getStringOfJson(i, _priceJson, "status"));
		}
	}
	$("#yinying1,#window_change").show();
}

function updateInfo(){
	
	var id=$("#updateId").val()
	if(IsEmpty(id)){
		art.dialog({fixed:true, lock: true,content:"修改出错",icon:'error',ok:true});	
		return false;
	}
	var shopId=$("#shopName2").val();
	var promPrice=$("#promPrice").val().replace(/\s/gi,'');
	var enableTime=$("#enableTime").val().replace(/\s/gi,'');
	var disableTime=$("#disableTime").val().replace(/\s/gi,'');
	var memo=$("#memo").val().replace(/\s/gi,'');
	var status=$("#status").val().replace(/\s/gi,'');
	if(checkNull(_goodsId,"产品",null)&&checkNull(shopId,"店铺","shopName2")&&_checkMoney(promPrice, false, "促销价格", "#promPrice")&&checkNull(enableTime, "生效时间", null)&&checkNull(disableTime, "失效时间", null)){
	}else{
		return false
	}
	var heads=new Array("shopId","promPrice","Status","effecDate","uneffedDate","memo","goodsId","id")
	var datas=new Array(shopId,promPrice,status,enableTime,disableTime,memo,_goodsId,id);
	var jsonParserStr = _getJsonParseEditStr(heads, datas);
	
	var dt = _editInfo("../goodsPromPrice/edit/editInfo", {"data":jsonParserStr})
			if(dt.state==0){
				getInfoOfGoodsId(null);
				$("#yinying1,#window_change").hide();
				resetForm();
				 }
}

function toSearch(){
	var goodsId=$("#goodSelecte").val();
	if(IsEmpty(goodsId)){
		alertErrorMessage("请选择商品")
		return false;
	}else{
		_goodsId=goodsId
		getGoodsInfo();
	}
	
}

function getGoodsInfo(){
	var json = _findInfo("../goods/find/id/"+_goodsId, null);
	 if(IsNotEmpty(json)&&json.state==0){
		$("#goodsName").val(_getStringOfJson(0, json, "name") )
		$("#goodsCode").val(_getStringOfJson(0, json, "code") )
		$("#goodsBarCode").val(_getStringOfJson(0, json, "barCode") )
		$("#goodsattr").val(_getStringOfJson(0, json, "mode") )
		$("#goodsSalePrice").val(_getStringOfJson(0, json, "SalePrice") )
	 getInfoOfGoodsId(1);
	 }
}

function returnURL(){
	window.location.href='products.html?flag=1'
}
		 

</script>
</head>
<body>
<div id="yinying1"></div>
<div id="yinying"></div>
<div id="goodsListPanel_yinying" class="yinying" style="z-index:499;"></div>
<div id="shopShow" class="hideDiv">
    <div style="float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;" > <span style="cursor: pointer;font-size: 14px;" onclick="closeShopShow();" >X</span> </div>
    <div class="bottom_search"><div class="serWrapper"><input type="text" id="searchName" class="txt"><strong class="refresh" onclick="$('#searchName').val('')">清空</strong></div><input class="common_btn" type="button" style="width:auto;margin-left:5px;" value="查询" onclick="search2()"></div>
    <table   id="shopList" cellpadding="4" cellspacing="0" border="1" width="100%">
    <thead>
    <tr>
    <th>店面ID</th>
    <th>店面名称</th>
    <th>电话</th>
    <th>操作</th>
    </tr>
    </thead>
    </table>
    	<div id="shopPager"></div>
    </div>
    
 <div class="hideDiv hideOver" id="window1">
 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
	<table id="actLargeList" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
    	<caption>服务类型       </caption>
    	<thead>
    	<tr>
        	<th>类别</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody>
        	
        </tbody>
    </table>
    <div id = "goodsTypePager" class="shopPager"></div>
</div>   
<!-- InstanceBeginEditable name="EditRegion3" -->
<form id="mainForm" >
  <div id="window_change" class="member_search hideDiv">
    <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
    <input type="hidden" id="doflag">
    <input type="hidden" id="shopflag">
    <input type="hidden" id="defaultCflag">
    <input type="hidden" id="updateId">
    <input type="hidden" id="updateDtId">
    <p>
      <label><span> 店面：</span>
        <select id="shopName2" onclick="showShopList(2)" style=";height:20px;">
        	<option value="">请选择店铺</option>
        </select>
      </label>
       <label><span> 促销价格：</span>
               <input type="text" id="promPrice">
      </label>
    </p>
	<p>
    
       <label><span>生效时间：</span>
			<input id="enableTime" class="doubledate " type="text" readonly=""> 
			     </label>
      <label><span>失效时间：</span>
		<input id="disableTime" class="doubledate " type="text" readonly="">
	      </label>
    </p>
     <p>
	<label><span>备注：</span>
        <textarea id="memo"></textarea>
      </label>
    </p>
    <p>
	<label><span>状态：</span>
        <select id="status"><option value="1" >启用</option><option value="0">停用</option></select>
      </label>
    </p>
    <div class="submit_btn">
      <input type="button" value="保存信息" class="common_btn" id="close_this" onclick="saveInfo()">
    </div>
  </div>
</form>
<div class="container" id="container">
  <div class="container_R fr">
	<div class="place">产品促销价格管理 <a class="goHome" onclick='returnURL()' href='javaScript:void(0)'>返回</a></div>

    <div class="member_search">
    <span> <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;"> 店面：</span><select id="shopName" onclick="showShopList(1)" style=";height:20px;" disabled="disabled" >  </select>
     <span>产品名称：</span> <select id="goodSelecte" onclick="openGoodsListPanel(this)" style=";height:20px;"><option value="">请选择商品</option><input class="btn" type="button" onclick="toSearch()" value="查询"/>
					</select>
</div>
   </br>
    <div class="member_search">
     <div class="knowPerson">
      <p class="knowAll" id="mInfo">
 
        <label> <span>商品编码：</span>
          <input type="text"  id="goodsCode" readonly="readonly">
        </label>
         <label> <span>商品名称：</span>
          <input type="text"  id="goodsName" readonly="readonly">
        </label>
          <label> <span>商品规格：</span>
          <input type="text"  id="goodsattr" readonly="readonly">
        </label>
        </p>
        <p class="knowAll" >
        <label> <span>商品条码：</span>
          <input type="text"  id="goodsBarCode" readonly="readonly">
        </label>
       
        <label> <span>商品零售价：</span>
          <input type="text"  id="goodsSalePrice" readonly="readonly">
        </label>
        </p>
      </div>
      </div>
     <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
    	<caption><strong>产品促销价格列表        <span id="sup">共0条</span></strong><input type="button" value="添加促销价格" class="common_btn addList" onclick="toAdd()"></caption>
    	<thead>
    	<tr>
        	<th>店铺名称</th>
        	<th>商品名称</th>
        	<th>商品名称</th>
        	<th>建议零售价</th>
        	<th>促销价格</th>
        	<th>生效时间</th>
        	<th>失效时间</th>
        	<th>备注</th>
        	<th>状态</th>
        	<th>经办人</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody></tbody>
    </table>
    <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager" style="float: right;"></div>
  </div>
  <div class="fc"></div>
</div>

<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/header.js"></script>
<script type="text/javascript" src="../js/left.js"></script>
<script type="text/javascript" src="../js/footer.js"></script>
<script type="text/javascript">
clearThis("absoluteTxt");
showTab(2,3);
</script>

		<div  style="z-index:500;" id="goodsListPanel" class="hideDiv">
			<div style="float: right; margin-bottom: 5px; width: 20px; height: 20px; line-height: 20px; text-align: center; background-color: #eee; margin-bottom: 5px; border: 1px solid #ccc;">
				<span id="goodsListPanel_close" style="cursor: pointer; font-size: 14px;">X</span>
			</div>
			<div class="bottom_search">
				<div class="serWrapper" >
					<input type="text" id="goodsListPanel_searchName" class="txt" >
					<strong class="refresh" onclick="$(this).prev().val('')">清空</strong>
				</div>
				<input type="button" id="goodsListPanel_search"
				style="width: auto; margin-left: 5px;" value="查询"
				class="common_btn">
			</div>
			<table cellpadding="4" cellspacing="0" border="1" width="100%">
				<thead>
					<tr>
						<th>商品Id</th>
						<th>商品名称</th>
						<th>商品扫描码</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="goodsListPanel_data" ></tbody>
			</table>
			<div id="goodsPager" class="pager" ></div>
		</div>

</body>
<!-- InstanceEnd --></html>
